<template>
  <div>
    <div class="crumbs">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item> <i class="el-icon-shopping-bag-2"></i> 人员列表 </el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="container">
      <div class="handle-box">
        <el-date-picker class="mr10" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd"
                        v-model="query.time">
        </el-date-picker>
        <el-input placeholder="请输入名字查询" v-model="query.souVal" class="handle-input mr10"></el-input>
        <el-button type="primary" icon="el-icon-search" @click="souClick">搜索</el-button>
      </div>
      <el-table v-loading="loading" :data="tableData" border class="table" style="width: 100%" ref="multipleTable"
                header-cell-class-name="table-header" @selection-change="SelectionChange">
        <el-table-column type="selection" width="55" align="center"></el-table-column>
        <el-table-column type="index" :index="tableIndex" label="序号" width="55" align="center"></el-table-column>
        <el-table-column prop="sbSname" label="人员姓名" width="180">
          <template slot-scope="scope">
            <el-link type="primary" :underline="false" @click="detailedClick(scope.row)">{{scope.row.sbSname}}</el-link>
          </template>
        </el-table-column>
        <el-table-column prop="sbSphone" label="电话" width="150"></el-table-column>
        <el-table-column prop="idCard" label="身份证号" width="200"></el-table-column>
        <el-table-column prop="sbCreateTime" label="创建时间"></el-table-column>
        <el-table-column prop="sbUpdateTime" label="更新时间"></el-table-column>
        <el-table-column fixed="right" label="操作" width="150" align="center">
          <template slot-scope="scope">
            <el-button type="text" icon="el-icon-delete-solid
" class="red" @click="delClick(scope.row)" :loading="scope.row.delLoad">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination">
        <el-pagination background layout="total, prev, pager, next" :current-page="query.page" :page-size="query.limit" :total="page.totalCount"
                       :pager-count="5" @current-change="PageChange" @prev-click="PageChange" @next-click="PageChange"></el-pagination>
      </div>
      <!-- 查看详情 -->
      <el-dialog title="人员信息" :visible.sync="nameflg" width="40%">
        <el-form :model="nameobj" ref="ruleForm" label-width="80px" class="demo-ruleForm">
          <el-form-item label="姓名" prop="name">
            <el-input v-model="nameobj.name"></el-input>
          </el-form-item>
          <el-form-item label="电话" prop="name">
            <el-input v-model="nameobj.tel"></el-input>
          </el-form-item>
          <el-form-item label="身份证号" prop="name">
            <el-input v-model="nameobj.carId"></el-input>
          </el-form-item>
          <el-form-item label="上传身份证复印件" prop="name">
            <el-image style="width: 100px; height: 100px" :src="nameobj.idcopy" :preview-src-list="[nameobj.idcopy]">
            </el-image>
          </el-form-item>
          <el-form-item label="上传合同协议图片" prop="name">
            <el-image style="width: 100px; height: 100px" :src="nameobj.xiecopy" :preview-src-list="[nameobj.xiecopy]">
            </el-image>
          </el-form-item>
        </el-form>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import { jdPersonnelListInit, jdPersonnelListDel } from '../../../api/index';

export default {
  data() {
    return {
      loading: false,
      query: {
        page: 1,
        limit: 10,
        time: [],
        souVal: ''
      },
      tableData: [],
      page: {
        totalCount: 100
      },
      //人员信息
      nameflg: false,
      nameobj: {},
    };
  },
  created() {
    this.getListData();
  },
  methods: {
    //列表信息
    getListData() {
      this.loading = true;
      let query = {
        startTime: this.query.time ? this.query.time[0] : '',
        endTime: this.query.time ? this.query.time[1] : '',
        kw: this.query.souVal,
        limit: this.query.limit,
        page: this.query.page,
      };
      jdPersonnelListInit(query).then((res) => {
        this.loading = false;
        if (res.code === 0) {
          res.recordList.map(item => {
            item['delLoad'] = false;
          })
          this.tableData = res.recordList;
          this.page.totalCount = res.totalCount;
        } else {
          this.$message(res.msg);
        }
      });
    },
    //序号
    tableIndex(index) {
      return (this.query.page - 1) * this.query.limit + index + 1;
    },
    //翻页
    PageChange(num) {
      this.query.page = num;
      this.getListData();
    },
    //搜索
    souClick() {
      this.query.page = 1;
      this.getListData();
    },
    //选中
    SelectionChange() { },
    //查看详情
    detailedClick(item) {
      this.nameflg = true;
      this.nameobj.name = item.sbSname;
      this.nameobj.tel = item.sbSphone;
      this.nameobj.carId = item.idCard;
      this.nameobj.idcopy = item.idcardPic;
      this.nameobj.xiecopy = item.sbContractPic;
    },
    //删除
    delClick(item) {
      this.$confirm("确定删除此条信息吗？", "提示", {
        confirmButtonText: '确定删除',
        cancelButtonText: '取消操作',
        type: 'warning',
      }).then(() => {
        item.delLoad = true;
        jdPersonnelListDel({
          baseId: item.sbId
        }).then(res => {
          item.delLoad = false;
          if (res.code == 0) {
            this.$message.success('操作成功');
            this.getListData();
          } else {
            this.$message(res.msg);
          }
        })
      })
    }
  }
};
</script>

<style scoped>
/deep/ :focus {
    outline: 0;
}
.handle-input {
    width: 300px;
    display: inline-block;
}
.nameDrawer {
    padding: 30px;
}
.elSelect {
    width: 100%;
}
.upload-demo {
    height: 32px;
}
.heng-border {
    height: 0.5px;
    margin-bottom: 30px;
}

/* 截图 */
.cropper-content .cropper {
    width: auto;
    height: 300px;
}
.refund-list {
    margin-bottom: 10px;
}
.payment_type {
    padding: 10px 0;
}
</style>
<style>
.nameDialogHead .headcol:nth-child(1) {
    font-size: 26px;
    font-weight: bold;
    margin-bottom: 20px;
}
.nameDialogHead .headcol:nth-child(1) span {
    font-size: 16px;
    margin-left: 20px;
}
.nameDialogHead .headcol:nth-child(2),
.nameDialogHead .headcol:nth-child(3) {
    font-size: 15px;
    color: #409eff;
    margin-bottom: 20px;
}
.GSList .el-col p:nth-child(1) {
    color: #999;
    margin-top: 10px;
}
.GSList .el-col .el-image {
    margin-right: 10px;
}
.red {
    color: #f56c6c;
}
</style>
